#ifndef __KERNEL_GLOBAL_H
#define __KERNEL_GLOBAL_H
#include "stdint.h"

//选择子的RPL字段
#define	 RPL0  0
#define	 RPL1  1
#define	 RPL2  2
#define	 RPL3  3

//选择子的TI字段
#define TI_GDT 0
#define TI_LDT 1

//定义不同的内核用的段描述符选择子
#define SELECTOR_K_CODE	   ((1 << 3) + (TI_GDT << 2) + RPL0)
#define SELECTOR_K_DATA	   ((2 << 3) + (TI_GDT << 2) + RPL0)
#define SELECTOR_K_STACK   SELECTOR_K_DATA 
#define SELECTOR_K_GS	   ((3 << 3) + (TI_GDT << 2) + RPL0)

////定义模块化的中断门描述符attr字段，attr字段指的是中断门描述符高字第8到16bit
#define	 IDT_DESC_P 1 
#define	 IDT_DESC_DPL0 0
#define	 IDT_DESC_DPL3 3
#define	 IDT_DESC_32_TYPE 0xE   // 32位的门
#define	 IDT_DESC_16_TYPE 0x6   // 16位的门，不用，定义它只为和32位门区分


#define	 IDT_DESC_ATTR_DPL0  ((IDT_DESC_P << 7) + (IDT_DESC_DPL0 << 5) + IDT_DESC_32_TYPE)  //DPL为0的中断门描述符attr字段
#define	 IDT_DESC_ATTR_DPL3  ((IDT_DESC_P << 7) + (IDT_DESC_DPL3 << 5) + IDT_DESC_32_TYPE)  //DPL为3的中断门描述符attr字段

#define NULL ((void*)0)
#define bool int
#define true 1
#define false 0

//定义eflages寄存器用的一些字段，含义见书p511
#define EFLAGS_MBS	(1 << 1)	// 此项必须要设置
#define EFLAGS_IF_1	(1 << 9)	// if为1,开中断
#define EFLAGS_IF_0	0		// if为0,关中断
#define EFLAGS_IOPL_3	(3 << 12)	// IOPL3,用于测试用户程序在非系统调用下进行IO
#define EFLAGS_IOPL_0	(0 << 12)	// IOPL0

struct vcpu {
   uint32_t eax;
   uint32_t ebx;
   uint32_t ecx;
   uint32_t edx;
   uint32_t esp;
   uint32_t ebp;
   uint32_t esi;
   uint32_t edi;

   uint32_t cs;
   uint32_t ss;
   uint32_t ds;
   uint32_t es;
   uint32_t fs;
   uint32_t gs;

   uint32_t eip;
   uint32_t eflags;
   
   uint32_t gdtr_base;
   uint16_t gdtr_limit;
   uint32_t idtr_base;
   uint16_t idtr_limit;
   uint16_t ldtr;
   uint16_t tr;
   
   uint32_t cr0;
   uint32_t cr1;
   uint32_t cr2;
   uint32_t cr3;
   uint32_t cr4;
   uint32_t h_cursor;
   uint32_t l_cursor;
   uint32_t CPL_;

   uint32_t* vm_phy_page_table;
   struct shadow_pt_map* shadow_pt_map_;

   struct PIT8253* pit;
   struct PIC8259A* pic;

   int pit_frequency_proportion;

};

#endif
